package cn.example.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * Swagger2的定制化配置类
 * @author yexi
 */

@Configuration
public class Swagger2Configuration {

    @Bean
    public Docket docket() {
        //一个生成指定的swagger风格的springmvc接口构建器
        Docket docket = new Docket(DocumentationType.SWAGGER_2);
        docket
                .enable(true)
                // 接口信息
                .apiInfo(apiInfo())
                // 开启api选择器，通过该选择器可以选择扫描指定位置的swagger注解
                .select()
                // 只扫描指定包中的swagger注解
                .apis(RequestHandlerSelectors.basePackage("cn.example.controller"))
                // 路径过滤器
                .paths(PathSelectors.any())
                .build()
                .groupName("API演示界面");
        return docket;
    }

    public ApiInfo apiInfo() {
        //负责此 API 的联系人信息
        Contact contact = new Contact("yexi", "www.yexi.com", "www.yexi.com");
        return new ApiInfoBuilder()
                .version("1.0")
                .contact(contact)
                .description("swagger的测试项目")
                .build();
    }


}
